package framework.automaton;

import java.util.HashMap;
import java.util.Map;


/**
 * This concrete class pairs every State object with a Visualization object.
 * 
 * @author Bill Ge, May Zhai, Alex Yoo
 */
public class Mapping {
	
	/** Map to keep track of the State->Visualization mappings,
	 *  with State as the key to a Visualization. */
	protected Map <State, Visualization> mapping;

	/** Constructor that constructs the mapping as a HashMap. */
	public Mapping(){	
		mapping = new HashMap <State, Visualization>();
	}	
	
	/**
	 * Pairs the given state to the given visualization.
	 * 
	 * @param state
	 * @param visualization
	 * @return true if the mapping was successfully added
	 * @return false if the state already has a mapping, or if anything is null
	 */
	public boolean addMapping(State state, Visualization visualization){
		if(mapping == null || state == null || visualization == null || mapping.containsKey(state)){
			return false;
		}
		mapping.put(state, visualization);
		return true;
	}
	
	/**
	 * Accessor Method returns the Visualization object that the given State
	 * object maps to.
	 * 
	 * @param state
	 * @param visualization
	 * @return the Visualization object that the given State object maps to.
	 */
	public Visualization getMapping (State state){
		return mapping.get(state);
	}
	
}